﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using QualityRpt.Utils;
using QualityRpt.Service;
using System.Collections;

namespace QualityRPT
{
    public partial class AirWireMidQuery : System.Web.UI.Page
    {
        int Suppliername = DeviceService.AIRWIRE_DEV;//标识 3 为天线厂商
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.h_dev.Value = Suppliername.ToString();
                DataTable sptable = DeviceSupplierService.GetListSupplierName(string.Empty, string.Empty, Suppliername);
                this.ajax_spin.DataSource = sptable;
                this.ajax_spin.DataTextField = "SUPPLIER_NAME"; this.ajax_spin.DataValueField = "ID";
                this.ajax_spin.DataBind();

				DataTable initscTable =  DeviceSpecService.GetBySpIn(string.Empty, Suppliername);
				this.ajax_scin.DataSource = initscTable;
				this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
				this.ajax_scin.DataBind ();

                DataTable rdtable = NetWorkPlazaService.GetRoadList();//获得所有路段
                this.ajax_rdin.DataSource = rdtable;
                this.ajax_rdin.DataTextField = "ORGAN_NAME"; this.ajax_rdin.DataValueField = "ORGAN_ID";
                this.ajax_rdin.DataBind();

				DataTable plTable = NetWorkPlazaService.GetListByRdIn(string.Empty);//默认获得所有广场
				this.ajax_plazain.DataSource = plTable;
				this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
				this.ajax_plazain.DataBind ();

                DataTable lanetable = AirwirePlazaService.GetAllLane();//获得所有车道
                this.ajax_lanein.DataSource = lanetable;
                this.ajax_lanein.DataTextField = "LANE_NO"; this.ajax_lanein.DataValueField = "LANE_NO";
                this.ajax_lanein.DataBind();

                this.textBoxStart.Text = DateTime.Now.ToString("yyyy-MM-dd 00:00");
                this.textBoxEnd.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            }
            else
            {
                strSpIn = Request.Params["ajax_spin"];
                strSpecIn = Request.Params["ajax_scin"];
                strRdIn = Request.Params["ajax_rdin"];
                strPlazaIn = Request.Params["ajax_plazain"];
                strLaneIn = Request.Params["ajax_lanein"];

                #region 设置选中状态
                //厂商选中状态
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    string[] selSpin = strSpIn.Split(new char[] { ',' });
                    Hashtable hashSelSp = new Hashtable();
                    for (int i = 0; i < selSpin.Length; i++)
                    {
                        hashSelSp.Add(selSpin[i], 0);
                    }
                    for (int i = 0; i < ajax_spin.Items.Count; i++)
                    {
                        if (hashSelSp.ContainsKey(ajax_spin.Items[i].Value))
                        {
                            ajax_spin.Items[i].Selected = true;
                        }
                    }
                }
                //路段选中状态
                if (strRdIn != null && strRdIn.Trim() != string.Empty)
                {
                    string[] selRdin = strRdIn.Split(new char[] { ',' });
                    Hashtable hashSelRd = new Hashtable();
                    for (int i = 0; i < selRdin.Length; i++)
                    {
                        hashSelRd.Add(selRdin[i], 0);
                    }
                    for (int i = 0; i < ajax_rdin.Items.Count; i++)
                    {
                        if (hashSelRd.ContainsKey(ajax_rdin.Items[i].Value))
                        {
                            ajax_rdin.Items[i].Selected = true;
                        }
                    }
                }
                //车道状态
                if (strLaneIn != null && strLaneIn.Trim() != string.Empty)
                {
                    string[] selLanein = strLaneIn.Split(new char[] { ',' });
                    Hashtable hashSelLane = new Hashtable();
                    for (int i = 0; i < selLanein.Length; i++)
                    {
                        hashSelLane.Add(selLanein[i], 0);
                    }
                    for (int i = 0; i < ajax_lanein.Items.Count; i++)
                    {
                        if (hashSelLane.ContainsKey(ajax_lanein.Items[i].Value))
                        {
                            ajax_lanein.Items[i].Selected = true;
                        }
                    }
                }
                //型号列表
                if (strSpIn == null)
                {
                    strSpIn = string.Empty;
                }
                DataTable sctable = DeviceSpecService.GetBySpIn(strSpIn, Suppliername);
                this.ajax_scin.DataSource = sctable;
                this.ajax_scin.DataTextField = "SPEC_NAME"; this.ajax_scin.DataValueField = "ID";
                this.ajax_scin.DataBind();
                //型号选中状态
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    string[] selScin = strSpecIn.Split(new char[] { ',' });
                    Hashtable hashSelSc = new Hashtable();
                    for (int i = 0; i < selScin.Length; i++)
                    {
                        hashSelSc.Add(selScin[i], 0);
                    }
                    for (int i = 0; i < ajax_scin.Items.Count; i++)
                    {
                        if (hashSelSc.ContainsKey(ajax_scin.Items[i].Value))
                        {
                            ajax_scin.Items[i].Selected = true;
                        }
                    }
                }
                //广场列表
                if (strRdIn == null)
                {
                    strRdIn = string.Empty;
                }
                DataTable plazatable = NetWorkPlazaService.GetListByRdIn(strRdIn);
                this.ajax_plazain.DataSource = plazatable;
                this.ajax_plazain.DataTextField = "ORGAN_NAME"; this.ajax_plazain.DataValueField = "ORGAN_ID";
                this.ajax_plazain.DataBind();
                //广场选中状态
                if (strPlazaIn != null && strPlazaIn.Trim() != string.Empty)
                {
                    string[] selPlazain = strPlazaIn.Split(new char[] { ',' });
                    Hashtable hashSelPlaza = new Hashtable();
                    for (int i = 0; i < selPlazain.Length; i++)
                    {
                        if (!hashSelPlaza.ContainsKey(selPlazain[i]))
                        {
                            hashSelPlaza.Add(selPlazain[i], 0);
                        }
                    }
                    for (int i = 0; i < ajax_plazain.Items.Count; i++)
                    {
                        if (hashSelPlaza.ContainsKey(ajax_plazain.Items[i].Value))
                        {
                            ajax_plazain.Items[i].Selected = true;
                        }
                    }
                }
                #endregion
            }
        }
        DateTime startTime; DateTime endTime; string strSpIn;
        string strSpecIn; string strRdIn; string strPlazaIn;
        string strLaneIn; int istatType = 0;
        public bool hasUnread = false;
        private void BindParams()
        {
            startTime = new DateTime(2013, 12, 01);
            //endTime = new DateTime(2013, 12, 09);
            string strStartTime = Request.Params["textBoxStart"]; string strEndTime = Request.Params["textBoxEnd"];
            if (strStartTime != null && strStartTime != string.Empty)
            {
                startTime = DateTime.Parse(strStartTime);
            }
            if (strEndTime != null && strEndTime != string.Empty)
            {
                endTime = DateTime.Parse(strEndTime).AddSeconds(59);
            }
            string strHasUnread = Request.Params["cb_hasunread"];
            hasUnread = strHasUnread == "1" ? true : false;
            string strStatType = Request.Params["sel_statTType"];
            if (strStatType != null && strStatType.Trim() != string.Empty)
            {
                istatType = Convert.ToInt32(strStatType);
            }
        }
        private void BindData()
        {
            BindParams();
            DateTime trackStart = DateTime.Now;
            StringBuilder sbGroupTitle = new StringBuilder();
            StringBuilder sbGroupNameTitle = new StringBuilder();
            bool nogroup = true;
            if (strRdIn != null && strRdIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("路段,"); ; nogroup = false;
                sbGroupNameTitle.Append("ROAD_NAME,");
            }
            if (strSpIn != null && strSpIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("厂商,"); nogroup = false;
                sbGroupNameTitle.Append("SUPPLIER_NAME,");
            }
            if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
            {
                sbGroupTitle.Append("型号,"); nogroup = false;
                sbGroupNameTitle.Append("SPEC_NAME,");
            }
            switch (istatType)
            {
                case 1:
                    sbGroupTitle.Append("年,月,"); sbGroupNameTitle.Append("STYEAR,STMONTH,");
                    break;
                case 2:
                    sbGroupTitle.Append("年,周,"); sbGroupNameTitle.Append("STYEAR,STWEEK,");
                    break;
                case 3:
                    sbGroupTitle.Append("年,月,日,"); sbGroupNameTitle.Append("STYEAR,STMONTH,STDAY,");
                    break;
            }
            if (nogroup)
            {
                sbGroupTitle.Append("路段,厂商,型号,");
                sbGroupNameTitle.Append("ROAD_NAME,SUPPLIER_NAME,SPEC_NAME,");
            }
            //条件
            AutoColumns = sbGroupNameTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            AutoColumnTitles = sbGroupTitle.ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            this.repeater_title.DataSource = AutoColumnTitles; this.repeater_title.DataBind();
            statTable = AIRWIRETransByDayService.GetAIRStatByMQ(startTime, endTime, string.Empty, istatType, strSpIn, strSpecIn, strRdIn, strPlazaIn, strLaneIn, hasUnread);
            this.repeater_data.DataSource = statTable; this.repeater_data.DataBind();
            TimeSpan tsConsume = DateTime.Now - trackStart;
            this.span_t_consume.InnerText = "耗时" + tsConsume.TotalSeconds + "s"; ;
            #region 图表数据生成
            string name_column_name = string.Empty;
            if (statTable.Columns.Contains("SPEC_NAME"))
            {
                name_column_name = "SPEC_NAME";
            }
            else if (statTable.Columns.Contains("SUPPLIER_NAME"))
            {
                name_column_name = "SUPPLIER_NAME";
            }
            if (statTable.Columns.Contains("ROAD_NAME"))
            {
                if (name_column_name != string.Empty)
                {
                    name_column_name = "ROAD_NAME#|#" + name_column_name;
                }
                else
                {
                    name_column_name = "ROAD_NAME";
                }
            }
            string[] name_array = name_column_name.Split(new string[] { "#|#" },StringSplitOptions.None);
            StringBuilder sbSelExpress = new StringBuilder();
            for (int i = 0; i < name_array.Length; i++)
            {
                if (i > 0)
                {
                    sbSelExpress.Append(" AND ");
                }
                sbSelExpress.Append(name_array[i] + "='{" + i + "}'");
            }
            if (statTable.Columns.Contains("STYEAR") || statTable.Columns.Contains("STWEEK") || statTable.Columns.Contains("STMONTH")
                || statTable.Columns.Contains("STDAY"))
            {
                GOnePassChartType = "line"; GDevSucChartType = "line"; GDevExChartType = "line";
                GLExChartType = "line"; GUnreadChartType = "line";

                Hashtable g_datas = new Hashtable();
                List<string> total_cates = new List<string>(); List<string> total_names = new List<string>();
                for (int i = 0; i < statTable.Rows.Count; i++)
                {
                    StringBuilder sb_gcates = new StringBuilder();
                    DataRow cur_row = statTable.Rows[i];
                    if (statTable.Columns.Contains("STYEAR"))
                    {
                        sb_gcates.Append(cur_row["STYEAR"] + "年");
                    }
                    if (statTable.Columns.Contains("STMONTH"))
                    {
                        sb_gcates.Append(cur_row["STMONTH"] + "月");
                    }
                    if (statTable.Columns.Contains("STWEEK"))
                    {
                        sb_gcates.Append(cur_row["STWEEK"] + "周");
                    }
                    if (statTable.Columns.Contains("STDAY"))
                    {
                        sb_gcates.Append(cur_row["STDAY"] + "日");
                    }
                    if (g_datas.ContainsKey(sb_gcates.ToString()))
                    {
                        DataTable v_table = g_datas[sb_gcates.ToString()] as DataTable;
                        v_table.ImportRow(cur_row);
                        g_datas[sb_gcates.ToString()] = v_table;
                    }
                    else
                    {
                        total_cates.Add(sb_gcates.ToString());
                        DataTable v_table = statTable.Clone();
                        v_table.ImportRow(cur_row);
                        g_datas.Add(sb_gcates.ToString(), v_table);
                    }
                    string _curkey = string.Empty;
                    for (int k = 0; k < name_array.Length; k++)
                    {
                        if (k > 0)
                        {
                            _curkey += "#|#";
                        }
                        _curkey += cur_row[name_array[k]].ToString();
                    }
                    if (!total_names.Contains(_curkey))
                    {
                        total_names.Add(_curkey);
                    }
                }
                for (int i = 0; i < total_cates.Count; i++)
                {
                    if (i > 0)
                    {
                        GCategories.Append(",");
                    }
                    GCategories.Append("'" + total_cates[i] + "'");
                }
                for (int i = 0; i < total_names.Count; i++)
                {
                    if (i > 0)
                    {
                        GOnePassDatas.Append(","); GDevSucDatas.Append(",");
                        GDevExDatas.Append(","); GLExDatas.Append(",");
                        GUnreadDatas.Append(",");
                    }
                    GOnePassDatas.Append("{name:'" + total_names[i] + "',data:[");
                    GDevSucDatas.Append("{name:'" + total_names[i] + "',data:[");
                    GDevExDatas.Append("{name:'" + total_names[i] + "',data:[");
                    GLExDatas.Append("{name:'" + total_names[i] + "',data:[");
                    GUnreadDatas.Append("{name:'" + total_names[i] + "',data:[");
                    for (int k = 0; k < total_cates.Count; k++)
                    {
                        string d_onepass = "0"; string d_devsuc = "0";
                        string d_devex = "0"; string d_lex = "0";
                        string d_unread = "0";
                        if (g_datas.ContainsKey(total_cates[k]))
                        {
                            DataTable v_table = g_datas[total_cates[k]] as DataTable;
                            string selText = sbSelExpress.ToString();
                            string[] name_datas = total_names[i].Split(new string[] { "#|#" },StringSplitOptions.None);
                            for (int m = 0; m < name_datas.Length; m++)
                            {
                                selText = selText.Replace("{" + m + "}", name_datas[m]);
                            }
                            DataRow[] snRows = v_table.Select(selText.ToString());
                            if (snRows.Length > 0)
                            {
                                d_onepass = StringUtils.FormatRatio(snRows[0]["OnePass_Rate"]);
                                d_devsuc = StringUtils.FormatRatio(snRows[0]["DevSuc_Rate"]);
                                d_devex = StringUtils.FormatRatio(snRows[0]["DevEx_Rate"]);
                                d_lex = StringUtils.FormatRatio(snRows[0]["LEx_Rate"]);
                                if (hasUnread)
                                {
                                    d_unread = StringUtils.FormatRatio(snRows[0]["Unread_Rate"]);
                                }
                            }
                        }
                        if (k > 0)
                        {
                            GOnePassDatas.Append(","); GDevSucDatas.Append(",");
                            GDevExDatas.Append(","); GLExDatas.Append(",");
                            GUnreadDatas.Append(",");
                        }
                        GOnePassDatas.Append(d_onepass); GDevSucDatas.Append(d_devsuc);
                        GDevExDatas.Append(d_devex); GLExDatas.Append(d_lex);
                        GUnreadDatas.Append(d_unread);
                    }
                    GOnePassDatas.Append("]}"); GDevSucDatas.Append("]}");
                    GDevExDatas.Append("]}"); GLExDatas.Append("]}");
                    GUnreadDatas.Append("]}");
                }
            }
            else
            {
                GOnePassChartType = "column"; GDevSucChartType = "column"; GDevExChartType = "column";
                GLExChartType = "column"; GUnreadChartType = "column";
                GOnePassDatas.Append("{name:'比例',data:[");
                GDevSucDatas.Append("{name:'比例',data:[");
                GDevExDatas.Append("{name:'比例',data:[");
                GLExDatas.Append("{name:'比例',data:[");
                GUnreadDatas.Append("{name:'比例',data:[");
                for (int i = 0; i < statTable.Rows.Count; i++)
                {
                    DataRow cur_row = statTable.Rows[i];
                    if (i > 0)
                    {
                        GCategories.Append(",");
                        GOnePassDatas.Append(",");
                        GDevSucDatas.Append(",");
                        GDevExDatas.Append(",");
                        GLExDatas.Append(",");
                        GUnreadDatas.Append(",");
                    }
                    GCategories.Append("'");
                    for (int mm = 0; mm < name_array.Length; mm++)
                    {
                        if (mm > 0)
                        {
                            GCategories.Append("-");
                        }
                        GCategories.Append(cur_row[name_array[mm]].ToString());
                    }
                    GCategories.Append("'");
                    string d_onepass = string.Empty; string d_devsuc = string.Empty;
                    string d_devex = string.Empty; string d_lex = string.Empty;
                    string d_unread = string.Empty;
                    d_onepass = StringUtils.FormatRatio(cur_row["OnePass_Rate"]);
                    d_devsuc = StringUtils.FormatRatio(cur_row["DevSuc_Rate"]);
                    d_devex = StringUtils.FormatRatio(cur_row["DevEx_Rate"]);
                    d_lex = StringUtils.FormatRatio(cur_row["LEx_Rate"]);
                    if (hasUnread)
                    {
                        d_unread = StringUtils.FormatRatio(cur_row["Unread_Rate"]);
                    }
                    GOnePassDatas.Append(d_onepass);
                    GDevSucDatas.Append(d_devsuc);
                    GDevExDatas.Append(d_devex);
                    GLExDatas.Append(d_lex);
                    GUnreadDatas.Append(d_unread);
                }
                GOnePassDatas.Append("]}");
                GDevSucDatas.Append("]}");
                GDevExDatas.Append("]}");
                GLExDatas.Append("]}");
                GUnreadDatas.Append("]}");
            }
            #endregion
        }
        //图表相关变量
        public StringBuilder GCategories = new StringBuilder();
        public StringBuilder GOnePassDatas = new StringBuilder();
        public string GOnePassChartType = "column";//一次成功率
        public StringBuilder GDevSucDatas = new StringBuilder();
        public string GDevSucChartType = "column";//设备成功率
        public StringBuilder GDevExDatas = new StringBuilder();
        public string GDevExChartType = "column";//设备异常率
        public StringBuilder GLExDatas = new StringBuilder();
        public string GLExChartType = "column";//逻辑异常率
        public StringBuilder GUnreadDatas = new StringBuilder();
        public string GUnreadChartType = "column";//漏读率
        protected void ButtonQ_Click(object sender, EventArgs e)
        {
            BindData();
        }
        DataTable statTable = null;
        string[] AutoColumns = null;
        string[] AutoColumnTitles = null;
        /// <summary>
        /// 根据列名生成需要显示的分组列
        /// </summary>
        /// <param name="rIndex"></param>
        /// <returns></returns>
        public string GetAutoColumns(object rIndex)
        {
            StringBuilder sbText = new StringBuilder();
            if (AutoColumns != null && statTable != null)
            {
                for (int i = 0; i < AutoColumns.Length; i++)
                {
                    sbText.Append("<td>" + statTable.Rows[Convert.ToInt32(rIndex)][AutoColumns[i]] + "</td>");
                }
            }
            return sbText.ToString();
        }

        protected void ButtonExport_Click(object sender, EventArgs e)
        {
            if (statTable == null)
            {
                BindData();
                string checkDate = DateTime.Parse(textBoxStart.Text).ToString("yyyy年MM月dd日") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy年MM月dd日");
                string reportFile = Server.MapPath("/ReportTemplate/天线综合统计报表.xls");
                SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook(reportFile);

                if (statTable == null || statTable.Rows.Count == 0)
                {
                    Common.Utility.Alert("您查询的内容不存在！", this.Page);
                    return;
                }
                //设置虚拟数据表newtab存放所要的数据列
                DataTable newtab = new DataTable();
                //判断分组情况
                switch (istatType)
                {
                    case 1:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        break;
                    case 2:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("周");
                        break;
                    case 3:
                        newtab.Columns.Add("年份");
                        newtab.Columns.Add("月份");
                        newtab.Columns.Add("日");
                        break;
                }
                if (strRdIn != null && strRdIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("路段");
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("厂商");
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    newtab.Columns.Add("型号");
                }
                if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strRdIn == null || strRdIn.Trim() == string.Empty))
                {
                    newtab.Columns.Add("路段");
                    newtab.Columns.Add("厂商");
                    newtab.Columns.Add("型号");
                }
                newtab.Columns.Add("总交易量");
                newtab.Columns.Add("一次通过量");
                newtab.Columns.Add("一次通过率");
                newtab.Columns.Add("设备成功量");
                newtab.Columns.Add("设备成功率");
                newtab.Columns.Add("设备异常量");
                newtab.Columns.Add("设备异常率");
                newtab.Columns.Add("逻辑异常量");
                newtab.Columns.Add("逻辑异常率");
                if (hasUnread == true)
                {
                    newtab.Columns.Add("漏读量");
                    newtab.Columns.Add("漏读率");
                }
                //遍历源数据表对新数据表各行进行赋值
                for (int i = 0; i < statTable.Rows.Count; i++)
                {
                    DataRow newRow = newtab.NewRow();
                    switch (istatType)
                    {
                        case 1:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            break;
                        case 2:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["周"] = statTable.Rows[i]["STWEEK"];
                            break;
                        case 3:
                            newRow["年份"] = statTable.Rows[i]["STYEAR"];
                            newRow["月份"] = statTable.Rows[i]["STMONTH"];
                            newRow["日"] = statTable.Rows[i]["STDAY"];
                            break;
                    }
                    if (strRdIn != null && strRdIn.Trim() != string.Empty)
                    {
                        newRow["路段"] = statTable.Rows[i]["ROAD_NAME"];
                    }
                    if (strSpIn != null && strSpIn.Trim() != string.Empty)
                    {
                        newRow["厂商"] = statTable.Rows[i]["SUPPLIER_NAME"];
                    }
                    if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                    {
                        newRow["型号"] = statTable.Rows[i]["SPEC_NAME"];
                    }
                    if ((strSpIn == null || strSpIn.Trim() == string.Empty) && (strSpecIn == null || strSpecIn.Trim() == string.Empty) && (strRdIn == null || strRdIn.Trim() == string.Empty))
                    {
                        newRow["路段"] = statTable.Rows[i]["ROAD_NAME"];
                        newRow["厂商"] = statTable.Rows[i]["SUPPLIER_NAME"];
                        newRow["型号"] = statTable.Rows[i]["SPEC_NAME"];
                    }
                    newRow["总交易量"] = statTable.Rows[i]["TRANSCOUNT"];
                    newRow["一次通过量"] = statTable.Rows[i]["ONEPASS_TRANSCOUNT"];
                    newRow["一次通过率"] = statTable.Rows[i]["ONEPASS_RATE"];
                    newRow["设备成功量"] = statTable.Rows[i]["DEVSUC_TRANSCOUNT"];
                    newRow["设备成功率"] = statTable.Rows[i]["DEVSUC_RATE"];
                    newRow["设备异常量"] = statTable.Rows[i]["DEVEX_TRANSCOUNT"];
                    newRow["设备异常率"] = statTable.Rows[i]["DEVEX_RATE"];
                    newRow["逻辑异常量"] = statTable.Rows[i]["LEX_TRANSCOUNT"];
                    newRow["逻辑异常率"] = statTable.Rows[i]["LEX_RATE"];
                    if (hasUnread == true)
                    {
                        newRow["漏读量"] = statTable.Rows[i]["UNREAD_TRANSCOUNT"];
                        newRow["漏读率"] = statTable.Rows[i]["UNREAD_RATE"];
                    }
                    newtab.Rows.Add(newRow);
                }
                #region 拼表格名称
                string a = ""; string b = ""; string c = ""; string d = ""; string f = "";
                if (hasUnread)
                {
                    a = "含漏读";
                }
                else
                {
                    a = "无漏读";
                }
                switch (istatType)
                {
                    case 0://无分组                        
                        b = "无分组";
                        break;
                    case 1://按月                      
                        b = "按月";
                        break;
                    case 2://按周                        
                        b = "按周";
                        break;
                    case 3://按日                        
                        b = "按日";
                        break;
                }
                if (strSpIn != null && strSpIn.Trim() != string.Empty)
                {
                    c = "厂商";
                }
                if (strSpecIn != null && strSpecIn.Trim() != string.Empty)
                {
                    d = "型号";
                }
                if (strRdIn != null && strRdIn.Trim() != string.Empty)
                {
                    f = "路段";
                }
                #endregion
                string file_name = "天线设备综合统计" + a + b + c + d + f + "报表" + "(" + DateTime.Parse(textBoxStart.Text).ToString("yyyy-MM-dd_HH：mm：ss") + "-" + DateTime.Parse(textBoxEnd.Text).ToString("yyyy-MM-dd_HH：mm：ss") + ")" + ".xls";
                switch (istatType)
                {
                    case 0://无分组
                        {
                            #region 厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "F", "H", "J", "L", "N" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "F", "H", "J", "L", "N" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "E", "G", "I", "K", "M" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "E", "G", "I", "K", "M" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "E", "G", "I", "K", "M" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "F", "H", "J", "L", "N" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 1://按月
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 2://按周
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "G", "I", "K", "M", "O" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                    case 3://按日
                        {
                            #region  厂商、型号、路段排列组合的八种
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商、型号、路段都不为空
                            {
                                string[] aa = new string[] { "J", "L", "N", "P", "R" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);

                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商不为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn != null && strSpIn.Trim() != string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商不为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号为空、路段为空
                            {
                                string[] aa = new string[] { "J", "L", "N", "P", "R" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn == null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号为空、路段不为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn == null || strRdIn.Trim() == string.Empty))//厂商为空、型号不为空、路段为空
                            {
                                string[] aa = new string[] { "H", "J", "L", "N", "P" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            if ((strSpIn == null || strSpIn.Trim() == string.Empty) && strSpecIn != null && (strRdIn != null && strRdIn.Trim() != string.Empty))//厂商为空、型号不为空、路段不为空
                            {
                                string[] aa = new string[] { "I", "K", "M", "O", "Q" };
                                Common.Common.ExportData(Response, newtab, workbook, 0, file_name, checkDate, aa);
                            }
                            break;
                            #endregion
                        }
                }
            }
        }
    }
}